package com.hxexp.weixin.test;

import java.io.StringReader;

import javax.xml.bind.JAXBException;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.BlockJUnit4ClassRunner;

import com.hxexp.weixin.common.jaxb.JaxbUnmarshallerHelper;
import com.qq.weixin.mp.message.hxexp.model.receive.BaseMsgJaxb;
import com.qq.weixin.mp.message.hxexp.model.receive.TextMsgJaxb;

@RunWith(BlockJUnit4ClassRunner.class)
public class JaxbUnmarshallerHelperTester {
    @Test
    public void testUnmarshal() {
        String xml = "<xml>" +
                "<ToUserName><![CDATA[gh_ac216ed6e766]]></ToUserName>" +
                "<FromUserName><![CDATA[o5GuMs3VA_8xB6VCNKaTdFQHVQ_U]]></FromUserName>" +
                "<CreateTime>1428562454</CreateTime>" +
                "<MsgType><![CDATA[text]]></MsgType>" +
                "<Content><![CDATA[测试消息]]></Content>" +
                "<MsgId>6135629020427974281</MsgId>" +
                "</xml>";
        try {
            TextMsgJaxb txt = (TextMsgJaxb) JaxbUnmarshallerHelper.unmarshal(new StringReader(xml),
                    new Class<?>[] { BaseMsgJaxb.class, TextMsgJaxb.class });
            System.out.println("ToUserName: " + txt.getToUserName());
            System.out.println("FromUserName: " + txt.getFromUserName());
            System.out.println("CreateTime: " + txt.getCreateTime());
            System.out.println("MsgType: " + txt.getMsgType());
            System.out.println("Content: " + txt.getContent());
            System.out.println("MsgId: " + txt.getMsgId());
        } catch (JAXBException e) {
            e.printStackTrace();
        }
    }
}
